package com.example.drawing.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import androidx.appcompat.app.AppCompatActivity;

import com.example.drawing.R;
import com.example.drawing.view.MobileView;

public class Activity_3_Mobile extends AppCompatActivity {
    private MobileView mobileView;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_3_mobile);
//        setContentView(new MobileView(this));


        mobileView=(MobileView)findViewById(R.id.mobile_view);
        //mobileView = new MobileView(Activity_3_Mobile.this);


        Button middle = (Button) findViewById(R.id.middle);
        Button top = (Button) findViewById(R.id.top);
        Button bottom = (Button) findViewById(R.id.bottom);
        Button left = (Button) findViewById(R.id.left);
        Button right = (Button) findViewById(R.id.right);

        top.setOnClickListener(new BtnClickListener(0, -50));

        bottom.setOnClickListener(new BtnClickListener(0, 50));

        left.setOnClickListener(new BtnClickListener(-50,0));

        right.setOnClickListener(new BtnClickListener(50,0));


    }


    //定义一个内部类,实现View.OnClickListener接口,并重写onClick()方法
    class BtnClickListener implements View.OnClickListener
    {
        int x,y;

        public BtnClickListener(int x, int y) {
            this.x = x;
            this.y = y;
        }

        public BtnClickListener() {
        }

        @Override
        public void onClick(View v) {
            mobileView.mibile(x, y);
        }
    }
}